/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import dayjs from 'dayjs'

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'

export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
  return dayjs(date).format(format)
}

export function formatToTime(format = DATE_TIME_FORMAT): string {
  return dayjs().format(format)
}

export function formatCurrentTimeToString() {
  //暂时支持中文
  const formatDate = formatToTime('HH:mm-MM-D-d');
  const dateArr = formatDate.split('-');
  const getWeekStr = (day: string) => {
    switch (day) {
      case '1': return '星期一';
      case '2': return '星期二';
      case '3': return '星期三';
      case '4': return '星期四';
      case '5': return '星期五';
      case '6': return '星期六';
      case '7': return '星期七';

    }
  }
  return {
    time: dateArr[0],
    day: `${dateArr[1]}月${dateArr[2]}日`,
    week : getWeekStr(dateArr[3]),
  }
}

export const dateUtil = dayjs
